//
//  WebViewController.m
//  QRCodeManager
//
//  Created by Cosmin Stirbu on 4/17/13.
//  Copyright (c) 2013 Cosmin Stirbu. All rights reserved.
//

#import "WebViewController.h"

@interface WebViewController ()

@end

@implementation WebViewController

@synthesize url;

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    NSURL *myUrl = [NSURL URLWithString:url];
    _urlTextField.text = url;
    _urlTextField.inputView = [UIView new];
    [_webView loadRequest:[NSURLRequest requestWithURL:myUrl]];
}

- (void)viewWillDisappear:(BOOL)animated {
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
    [super viewWillDisappear:animated];
}

#pragma mark - User Interface

- (IBAction)backButtonTapped:(id)sender {
    [_webView goBack];
}

- (IBAction)forwardButtonTapped:(id)sender {
    [_webView goForward];
}

- (IBAction)refreshButtonTapped:(id)sender {
    [_webView reload];
}

#pragma mark - UIWebView

- (void)webViewDidStartLoad:(UIWebView *)webView {
    [_backButton setEnabled:[_webView canGoBack]];
    [_forwardButton setEnabled:[_webView canGoForward]];
    
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
    [_urlTextField resignFirstResponder];
}


- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
    _urlTextField.text = [[[webView request] URL] absoluteString];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidUnload {
    _webView = nil;
    _backButton = nil;
    _forwardButton = nil;
    _urlTextField = nil;
    [super viewDidUnload];
}
@end
